<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@include file="/WEB-INF/jsp/base.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>

<link rel="shortcut icon" href="favicon.ico">
<link href="css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
<link href="css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<!-- Data Tables -->
<link href="css/plugins/dataTables/dataTables.bootstrap.css"
	rel="stylesheet">
<link href="css/animate.min.css" rel="stylesheet">
<link href="./css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

<link href="css/style.min.css?v=4.0.0" rel="stylesheet">
<script src="./js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="./js/img_upload.js"></script>
<script type="text/javascript" src="./js/fileUploadUtil.js"></script>

<script type="text/javascript"></script>
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.5"></script>
<script src="js/plugins/jeditable/jquery.jeditable.js"></script>
<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="./js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="js/content.min.js?v=1.0.0"></script>
<script src="js/common.js"></script>
<style type="text/css">
.chanceTable {
	border-collapse: separate;
	border-spacing: 10px;
}
/* dataTables列内容居中 */
.table>tbody>tr>td {
	text-align: center;
}
/* dataTables表头居中 */
.table>thead:first-child>tr:first-child>th {
	text-align: center;
}
</style>

<script type="text/javascript">
	function FormatDate(date) {
		preClosingDate
		return date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
				+ date.getDate();
	}
</script>
<script type="text/javascript">
	var table;
	var darw = 0;
	$(function() {

		//提示信息
		var lang = {
			"sProcessing" : "<div style=\"float:right;width:50%\" >处理中...</div>",
			"sLengthMenu" : "每页 _MENU_ 项",
			"sZeroRecords" : "没有匹配结果",
			"sInfo" : "当前显示第 _START_ 至 _END_ 项，共 _TOTAL_ 项。",
			"sInfoEmpty" : "当前显示第 0 至 0 项，共 0 项",
			"sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
			"sInfoPostFix" : "",
			"sSearch" : "搜索:",
			"sUrl" : "",
			"sEmptyTable" : "表中数据为空",
			"sLoadingRecords" : "载入中...",
			"sInfoThousands" : ",",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "上页",
				"sNext" : "下页",
				"sLast" : "末页",
				"sJump" : "跳转"
			},
			"oAria" : {
				"sSortAscending" : ": 以升序排列此列",
				"sSortDescending" : ": 以降序排列此列"
			}
		};

		//初始化表格
		table = $("#chanceDataTable")
				.dataTable(
						{

							"fnDrawCallback" : function() {

								var api = this.api();
								var startIndex = api.context[0]._iDisplayStart;//获取到本页开始的条数
								api.column(0).nodes().each(function(cell, i) {
									cell.innerHTML = startIndex + i + 1;
								});

							},
							language : lang, //提示信息
							autoWidth : false, //禁用自动调整列宽
							stripeClasses : [ "odd", "even" ], //为奇偶行加上样式，兼容不支持CSS伪类的场合
							processing : true, //隐藏加载提示,自行处理

							serverSide : true, //启用服务器端分页
							searching : false, //禁用原生搜索
							orderMulti : false, //启用多列排序
							order : [], //取消默认排序查询,否则复选框一列会出现小箭头
							renderer : "bootstrap", //渲染样式：Bootstrap和jquery-ui
							pagingType : "simple_numbers", //分页样式：simple,simple_numbers,full,full_numbers
							"bLengthChange" : false,
							ordering : false, //关闭排序图标
							// bStateSave:true,  //刷新 停留在当前页
							ajax : function(data, callback, settings) {
								//封装请求参数
								var param = {};
								param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
								param.start = data.start;//开始的记录序号
								param.page = (data.start / data.length) + 1;//当前页码
								// param.darw=darw;  //计数器

								var ChanceName = $("#serachChanceName").val()
										.trim();
								if (ChanceName != null && ChanceName != "") {
									param.chanceName = ChanceName;
								}

								//console.log(param);
								//ajax请求数据
								$
										.ajax({
											type : "POST",
											url : "queryChanceList.do",
											cache : false, //禁用缓存
											data : param, //传入组装的参数
											dataType : "json",
											success : function(result) {

												//console.log(result);
												//setTimeout仅为测试延迟效果
												//封装返回数据
												var returnData = {};
												draw = result.draw;//后台返回的计数器
												returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
												returnData.recordsTotal = result.total;//返回数据全部记录
												returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
												returnData.data = result.data;//返回的数据列表

												//console.log(returnData);
												//调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染
												//此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
												callback(returnData);
											},
											error : function() {
												sweetAlert("异常", "网络出现异常!",
														"error");
											}
										});
							},
							//列表表头字段
							columns : [

							{
								"data" : null
							},

							{
								"data" : "chanceId",
								"visible" : false
							}, {
								"data" : "chanceName"
							}, {
								"data" : "preSales"
							}, {
								"data" : "preClosingDate"
							}, {
								"data" : "salesPhase"
							}, {
								"data" : "intentionProducts"
							}, {
								"data" : "opportunitySource"
							}, {
								"data" : "status"
							} ],
							columnDefs : [
									{
										"targets" : [ 9 ], //第14列加一条 自定义列
										"data" : "chanceId", //数据列名
										"render" : function(data, type, full) { //返回自定义的内容
											//console.log(data);
											/* */
											return "<a class=\"btn btn-info btn-xs\" data-toggle=\"modal\"  onclick=\"chanceDetail('"
													+ data
													+ "')\"   href=\"javascript:void(0);\"> 详情<\a>"
													+ "&nbsp;<a class=\"btn btn-primary  btn-xs\"   href=\"javascript:void(0);\" onclick=\"modifyModal('"
													+ data
													+ "')\">编辑<\a>&nbsp;"
													+ "<a class=\"btn btn-danger  btn-xs\" href=\"javascript:void(0);\" onclick=\"deleteChance('"
													+ data + "')\">删除<\a>";

										}

									}, {

										"targets" : [ 8 ], //第12列加一条 自定义列
										//数据列名
										"render" : function(data, type, full) {
											var status = "";
											if (data == 0) {
												status = "启用";

											} else if (data == 2){
												status = "禁用";
											}
											return status;

										}

									}, {
										"targets" : [ 4 ],
										"render" : function(data, type, full) {
											var preDate = new Date(data);
											return FormatDate(preDate);
										}
									}

							]
						})//.api();
		//此处需调用api()方法,否则返回的是JQuery对象而不是DataTables的API对象

	});
</script>
</head>
<body class="gray-bg">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-title">
					<h5>机会列表</h5>
					<div class="ibox-content">
						<div class="input-group col-md-3"
							style="margin-top: 0px; positon: relative; float: left; bottom: -5px;">
							<input id="serachChanceName" type="text" class="form-control "
								placeholder="请输入关键字（机会名称、备注）"/ > <span
								class="input-group-btn">
								<button onclick="search()" class="btn btn-info btn-search">查询</button>
								<button class="btn btn-info btn-search"
									href="javascript:void(0);" onclick="addChanceBefore()"
									style="margin-left: 5px">添加</button>
							</span>
						</div>
						<table id="chanceDataTable"
							class="table table-striped table-bordered table-hover dataTables-example">
							<thead>
								<tr>
									<th>序号</th>
									<th></th>
									<th>机会名称</th>
									<th>预销售额</th>
									<th>预成交日</th>
									<th>销售阶段</th>
									<th>意向产品</th>
									<th>机会来源</th>
									<th>状态</th>
									<th>操作</th>
								</tr>
							</thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!--添加的模态层  -->
	<div class="modal fade  " id='addChanceModal'>
		<div class="modal-dialog" style="width: 550px; height: 500px;">
			<div class="modal-content">
				<div class="modal-header">
					<button class="close" data-dismiss='modal'>×</button>
					<h2 class="modal-title" align="center">添加机会信息</h2>
				</div>

				<div class="modal-body" align="center">

					<form id="chanceFormInfo">
						<table id="addTable" class="chanceTable">
							<tr>
								<td align="right">机会名称<span style="color: red;">*</span>：
								</td>
								<td style="width: 350px;"><input type="text"
									name="chanceName" id="chanceName" class="form-control"
									placeholder="请输入机会名称"></td>
							</tr>
							<tr>
								<td align="right">预销售额<span style="color: red;">*</span>：
								</td>
								<td><input type="number" name="preSales" id="preSales"
									class="form-control" placeholder="请输入预销售额"></td>
							</tr>
							<tr>
								<td align="right">意向产品<span style="color: red;">*</span>：
								</td>
								<td><select class="form-control" name="intentionProducts"
									id="intentionProducts">
										<option value="">-请选择-</option>
										<c:forEach var="product" items="${productList }"
											varStatus="status">
											<%-- <option value="${status.index }">${product.productName }</option> --%>
											<%-- <option value="${product.productId} ">${product.productName }</option> --%>
											<option value="${product.productName } ">${product.productName }</option>
										</c:forEach>
								</select></td>
							</tr>
							<tr>
								<td align="right">预成交日<span style="color: red;">*</span>：
								</td>
								<td><input type="text" name="preClosingDate"; readonly="readonly"
									class="form-control"
									onClick="WdatePicker({lang:'zh-cn',dateFmt:'yyyy-MM-dd'})"
									placeholder="请输入预成交日" id="preClosingDate"></td>
							</tr>
							<tr>
								<td align="right">销售阶段<span style="color: red;">*</span>：
								</td>
								<td><select class="form-control" name="salesPhase"
									id="salesPhase">
										<option value="">-请选择-</option>
										<option>获取机会</option>
										<option>接触客户</option>
										<option>客户见面</option>
										<option>合同调整</option>
										<option>合同确认</option>
										<option>签合同</option>
										<option>付款</option>
										<option>确认收款</option>
										<option>赢单</option>
										<option>输单</option>
										<option>作废</option>
								</select></td>
							</tr>
							<tr>
								<td align="right">机会来源<span style="color: red;">*</span>：
								</td>
								<td><select class="form-control" name="opportunitySource"
									id="opportunitySource">
										<option>录入机会</option>
										<option>客户介绍</option>
										<option>市场活动</option>
										<option>其他</option>
								</select></td>
							</tr>
							<tr>
								<td align="right">备注：</td>
								<td><textarea class="form-control" rows="3" cols="10" style="resize:none;"
										name="remark" id="remark"></textarea></td>
							</tr>

						</table>
						<!-- <input type="text" id="graphicsText" name="graphicsText"> -->
						<input type="hidden" name="status" value="0">
					</form>

				</div>
				<div class="modal-footer" align="center">
					<div align="center">

						<button class="btn btn-primary" id="btnAddChance"
							onclick="addChance()">确认</button>
						<!-- <button class="btn btn-default"
							onclick="closeModal(addChanceModal)" id="btnAddClose">关闭</button> -->
					</div>
				</div>
			</div>
		</div>
	</div>

	<!--修改的模态层  -->
	<div class="modal fade  " id='modifyChanceModal'>
		<div class="modal-dialog" style="width: 550px; height: 500px;">
			<div class="modal-content">
				<div class="modal-header">
					<button class="close" data-dismiss='modal'>×</button>
					<h2 class="modal-title" align="center">编辑机会信息</h2>
				</div>

				<div class="modal-body" align="center">

					<form id="modifyChanceForm">
						<table id="modifyTable" class="chanceTable" >
							<tr>
								<td align="right" >机会名称<span
									style="color: red;">*</span>：
								</td>
								<td style="width: 300px"><input type="text"
									name="chanceName" id="mchanceName" class="form-control"
									placeholder="请输入机会名称"></td>
							</tr>
							<tr>
								<td align="right">预销售额<span style="color: red;">*</span>：
								</td>
								<td><input type="number" name="preSales" id="mpreSales"
									class="form-control" placeholder="请输入预销售额"></td>
							</tr>
							<tr>
								<td align="right">意向产品<span style="color: red;">*</span>：
								</td>
								<td><select class="form-control" name="intentionProducts"
									id="mintentionProducts">
										<option value="">-请选择-</option>
										<c:forEach var="product" items="${productList }"
											varStatus="status">
											<%-- <option value="${status.index }">${product.productName }</option> --%>
											<%-- <option value="${product.productId} ">${product.productName }</option> --%>
											<option value="${product.productName }	">${product.productName }</option>
										</c:forEach>
								</select></td>
							</tr>
							<tr>
								<td align="right">预成交日<span style="color: red;">*</span>：
								</td>
								<td><input type="text" name="preClosingDate" readonly="readonly"
									class="form-control"
									onClick="WdatePicker({lang:'zh-cn',dateFmt:'yyyy-MM-dd'})"
									placeholder="请输入预成交日" id="mpreClosingDate"></td>
							</tr>
							<tr>
								<td align="right">销售阶段<span style="color: red;">*</span>：
								</td>
								<td><select class="form-control" name="salesPhase"
									id="msalesPhase">
										<option value="">-请选择-</option>
										<option>获得机会</option>
										<option>接触客户</option>
										<option>客户见面</option>
										<option>合同调整</option>
										<option>合同确认</option>
										<option>签合同</option>
										<option>付款</option>
										<option>确认收款</option>
										<option>赢单</option>
										<option>输单</option>
										<option>作废</option>
								</select></td>
							</tr>
							<tr>
								<td align="right">机会来源<span style="color: red;">*</span>：
								</td>
								<td><select class="form-control" name="opportunitySource"
									id="mopportunitySource">
										<option value="录入机会">录入机会</option>
										<option value="客户介绍">客户介绍</option>
										<option value="市场活动">市场活动</option>
										<option value="其他">其他</option>
								</select></td>
							</tr>

							<tr>
								<td align="right">状态：</td>
								<td><select name="status" id="mstatus" class="form-control">
										<option value="0">启用</option>
										<option value="2">禁用</option>
								</select></td>
							</tr>
							<tr style="height: 70px">
								<td align="right">备注：</td>
								<td><textarea class="form-control" rows="3" cols="10" style="resize:none;"
										name="remark" id="mremark"></textarea></td>
							</tr>

						</table>
						<input type="hidden" name="chanceId" id="mchanceId">
					</form>

				</div>
				<div class="modal-footer" align="center">
					<div align="center">
						<button class="btn btn-primary" id="btnAddChance"
							onclick="modifyChance()">确认</button>
					</div>
				</div>
			</div>
		</div>
	</div>


	<!--详细信息的模态层  -->
	<div class="modal fade  " id='chanceDetailModal'>
		<div class="modal-dialog" style="width: 800px; height: 500px;">
			<div class="modal-content">
				<div class="modal-header">
					<button class="close" data-dismiss='modal'>×</button>
					<h2 class="modal-title" align="center">机会信息详情</h2>
				</div>

				<div class="modal-body" align="center">

					<form>

						<table id="modifyTable" class="chanceTable">
							<tr>
								<td align="right">机会名称：</td>
								<td><span id="schanceName" class="form-control"
									disabled="disabled"></span></td>
								<td align="right">预销售额：</td>
								<td><span id="spreSales" class="form-control"
									disabled="disabled"></span></td>
							</tr>
							<tr>
								<td align="right">意向产品：</td>
								<td><span id="sintentionProducts" class="form-control"
									disabled="disabled"></span></td>
								<td align="right">预成交日：</td>
								<td><span class="form-control" id="spreClosingDate"
									disabled="disabled"></span></td>
							</tr>
							<tr>
								<td align="right">销售阶段：</td>
								<td><span class="form-control" id="ssalesPhase"
									disabled="disabled"> </span></td>
								<td align="right">机会来源：</td>
								<td><span id="sopportunitySource" class="form-control"
									disabled="disabled"></span></td>
							</tr>
							<tr>
								<td align="right">创建人：</td>
								<td><span id="screatePeople" class="form-control"
									disabled="disabled"></span></td>
								<td align="right">创建时间：</td>
								<td><span id="screateDate" class="form-control"
									disabled="disabled"></span></td>
							</tr>
							<tr>
								<td align="right">所属部门：</td>
								<td width="250px"><span id="ssection" width="250"
									class="form-control" disabled="disabled"></span></td>
								<td align="right">状态：</td>
								<td width="250px"><span class="form-control" id="sstatus"
									disabled="disabled"></span></td>
							</tr>
						</table>
						<table id="modifyTable">
							<tr>
								<td width="80px" align="right">备注：</td>
								<td><textarea class="form-control" rows="3" cols="10"
										style="width: 590px;resize:none;" name="remark" id="sremark"
										disabled="disabled"></textarea></td>
							</tr>
						</table>
						<!-- 	<input type="hidden"  name="chanceId" id="mchanceId" > -->
					</form>

				</div>
				<div class="modal-footer" align="center">
					<div align="center">
						<button class="btn btn-primary" id="btnAddChance"
							onclick="closeModal(chanceDetailModal)">确认</button>
					</div>
				</div>
			</div>
		</div>
	</div>







	<script>
		//显示modal
		function showModal(modal) {
			$(modal).modal("show");
		}
		//隐藏modal
		function closeModal(modal) {
			$(modal).modal("hide");
		}

		//添加机会前清空添加模态框的数据
		function addChanceBefore(){
			$("#chanceName").val("");
			$("#preSales").val("");
			$("#intentionProducts").val("");
			$("#preClosingDate").val("");
			$("#salesPhase").val("");
			$("#remark").val("");
			showModal(addChanceModal);
		}
		//添加机会
		function addChance() {
			var chanceName = $("#chanceName");
			var preSales = $("#preSales");
			var intentionProducts = $("#intentionProducts");
			var preClosingDate = $("#preClosingDate");
			var salesPhase = $("#salesPhase");
			var opportunitySource = $("#opportunitySource");
			var remark = $("#remark");

			if (chanceName.val().trim() == "") {
				swal("提示", "机会名称不能为空!", "warning");
				return false;
			}

			if (preSales.val().trim() == "") {
				swal("提示", "预销售额不能为空!", "warning");
				return false;
			}
			if (intentionProducts.val().trim() == "") {
				swal("提示", "请选择意向产品!", "warning");
				return false;
			}
			if (preClosingDate.val().trim() == "") {
				swal("提示", "预成交日不能为空!", "warning");
				return false;
			}
			if (salesPhase.val().trim() == "") {
				swal("提示", "请选择销售阶段!", "warning");
				return false;
			}
			if (opportunitySource.val().trim() == "") {
				swal("提示", "机会来源不能为空!", "warning");
				return false;
			}
			/* if(remark.val().trim()==""){
				swal("提示","备注不能为空!","warning");
				return false;
			} */

			//执行添加
			$.ajax({
				url : "addChance.do",
				data : $("#chanceFormInfo").serializeArray(),
				dataType : "json",
				type : "post",
				success : function(result) {
					if (result.flag == 1) {
						swal({
							title : "提示",
							text : result.msg,
							type : "success",
							confirmButtonColor : "#DD6B55",
							confirmButtonText : "确定"
						}, function() {
							$('#chanceFormInfo')[0].reset();
							$("#addChanceModal").modal("hide");
							search();
						});

					} else if (result.flag == 0) {
						swal("异常", result.msg, "error");
					} else {
						swal("错误", result.msg, "error");
					}					
				},
				error : function() {
					swal("错误", "系统出现错误!", "error");
				}
			});
		}

		//修改机会信息的模态层
		function modifyModal(chanceId) {
			$
					.ajax({
						url : "modifyChanceQuery.do",
						data : {
							"chanceId" : chanceId
						},
						dataType : "json",
						type : "post",
						success : function(result) {
							if (result.flag == 1) {
								$("#mchanceId").val(result.chance.chanceId);
								$("#mchanceName").val(result.chance.chanceName);
								$("#mpreSales").val(result.chance.preSales);
								//$("#mintentionProducts").val(result.chance.intentionProducts);
								//遍历产品select

								$("#mintentionProducts option")
										.each(
												function() {
													if ($(this).text().trim() == result.chance.intentionProducts
															.trim()) {
														$(this).prop(
																"selected",
																"selected");

													}
												});

								var preClosingDate = new Date(
										result.chance.preClosingDate);//时间戳转换为java.util.date
								preClosingDate = FormatDate(preClosingDate);//抽取出来年月日
								$("#mpreClosingDate").val(preClosingDate);
								//$("#msalesPhase").val(result.chance.salesPhase);

								//遍历机会来源selec
								$("#msalesPhase option")
										.each(
												function() {
													if ($(this).text() == result.chance.salesPhase) {
														$(this).prop(
																"selected",
																"selected");
														//break;

													}
												});

								$("#mopportunitySource").val(
										result.chance.opportunitySource);

								$("#mremark").val(result.chance.remark);
								//遍历状态select
								$("#mstatus option").each(function() {
									if ($(this).val() == result.chance.status) {
										$(this).prop("selected", "selected");
										//break;
									}
								});

								$("#modifyChanceModal").modal("show");

							} else if (result.flag == 0) {
								swal("异常", "暂无数据,请稍后再试!", "warning")
							}

						},
						error : function() {
							swal("错误", "系统异常,请稍后再试!", "error")
						}
					});
		}

		//修改机会
		function modifyChance() {

			var chanceName = $("#mchanceName");
			var preSales = $("#mpreSales");
			var intentionProducts = $("#mintentionProducts");
			var preClosingDate = $("#mpreClosingDate");
			var salesPhase = $("#msalesPhase");
			var opportunitySource = $("#mopportunitySource");
			var remark = $("#mremark");

			if (chanceName.val().trim() == "") {
				swal("提示", "机会名称不能为空!", "warning");
				return false;
			}

			if (preSales.val().trim() == "") {
				swal("提示", "预销售额不能为空!", "warning");
				return false;
			}
			if (intentionProducts.val().trim() == "") {
				swal("提示", "请选择意向产品!", "warning");
				return false;
			}
			if (preClosingDate.val().trim() == "") {
				swal("提示", "预成交日不能为空!", "warning");
				return false;
			}
			if (salesPhase.val().trim() == "") {
				swal("提示", "请选择销售阶段!", "warning");
				return false;
			}
			if (opportunitySource.val().trim() == "") {
				swal("提示", "机会来源不能为空!", "warning");
				return false;
			}

			$.ajax({
				url : "modifyChance.do",
				data : $("#modifyChanceForm").serializeArray(),
				type : "post",
				dataType : "json",
				success : function(result) {
					if (result.flag == 1) {
						swal({
							title : "提示",
							text : result.msg,
							type : "success",
							confirmButtonColor : "#DD6B55",
							confirmButtonText : "确定",
							closeOnConfirm : true
						}, function() {
							$("#modifyChanceModal").modal("hide");
							search();
						});

					} else if (flag == 0) {
						swal("异常", result.msg, "error");
					} else {
						swal("异常", "程序异常,请稍后再试!", "error");
					}

				},
				error : function() {
					swal("异常", "程序异常,请稍后再试!", "error");
				}

			});

		}

		//删除数据提示函数
		function deleteChance(chanceId) {
			var AjaxURL = "deleteChance.do";
			swal({
				title : "提示",
				text : "您确定要删除这条信息吗！",
				type : "warning",
				showCancelButton : true,
				confirmButtonColor : "#DD6B55",
				confirmButtonText : "删除",
				cancelButtonText : "取消",
				closeOnConfirm : false
			}, function() {
				//如果确认，异步处理删除动作
				$.ajax({
					type : "post",
					dataType : "json",
					url : AjaxURL,
					data : {
						"chanceId" : chanceId
					},
					success : function(data) {
						if (data.code == "success") {
							swal({
								title : "提示",
								text : data.msg,
								type : "success",
								confirmButtonColor : "#DD6B55",
								confirmButtonText : "确定",
								closeOnConfirm : true
							}, function() {
								search()
							});
						} else {
							swal("异常", data.msg, "error")
						}
					},
					error : function() {
						swal("错误", "未知错误请联系管理员！", "error")
					}
				});
			});
		}

		//查看机会详细信息
		function chanceDetail(chanceId) {
			$.ajax({
				url : "modifyChanceQuery.do",
				data : {
					"chanceId" : chanceId
				},
				dataType : "json",
				type : "post",
				success : function(result) {
					if (result.flag == 1) {
						//$("#schanceId").text(result.chance.chanceId);
						$("#schanceName").text(result.chance.chanceName);
						$("#spreSales").text(result.chance.preSales);
						$("#sintentionProducts").text(
								result.chance.intentionProducts);
						//遍历产品select

						var preClosingDate = new Date(
								result.chance.preClosingDate);//时间戳转换为java.util.date
						preClosingDate = FormatDate(preClosingDate);//抽取出来年月日
						$("#spreClosingDate").text(preClosingDate);
						$("#ssalesPhase").text(result.chance.salesPhase);

						$("#sopportunitySource").text(
								result.chance.opportunitySource);

						$("#sremark").text(result.chance.remark);

						var createDate = new Date(result.chance.createDate);//时间戳转换为java.util.date
						createDate = FormatDate(createDate);//抽取出来年月日

						$("#screateDate").text(createDate);
						$("#ssection").text(result.chance.dept.deptName);
						$("#screatePeople").text(result.chance.createPeople);

						var status = "";
						if (result.chance.status == 0) {
							status = "启用";
						} else if (result.chance.status == 2){
							status = "禁用";
						}

						$("#sstatus").text(status);
						$("#chanceDetailModal").modal("show");

					} else if (result.flag == 0) {
						swal("异常", "暂无数据,请稍后再试!", "warning")
					}
				},
				error : function() {
					swal("错误", "系统异常,请稍后再试!", "error")
				}
			});
		}
		//搜索
		function search() {
			/* var oSettings = table.fnSettings();  
			oSettings._iDisplayStart = 0;  
			table.fnDraw(oSettings);   */
			table.fnDraw();
		}
	</script>
</body>
</html>